﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using WarehouseManagement.BusinessLogic.BC;
using WarehouseManagement.DataAccess;

namespace WarehouseManagement.BusinessLogic.DTO
{
    public class ImportDetailDTO : ImportDetailViewItemBase
    {

        public decimal TotalUnitPrice
        {
            get
            {
                return UnitPriceAfterTax * (decimal)Quantity * ExchangeRate;
            }

        }

        public new decimal UnitPriceAfterTax
        {
            get
            {
                return (OriginPrice + ((decimal)Tax / 100 * OriginPrice) + ShippingFee);
            }
        }

        public ImportDetailDTO()
        {
            this.Id = Guid.NewGuid();


            //CurrencyBC bc = new CurrencyBC();
            //var item = bc.GetCurrencyByCode("VND");
            //if (item != null)
            //{

            //    this.us = item.CurrencyId;

            //}

            //this.ExchangeRate = 1;


            this.Quantity = 1;
        }


       
        
        public string MerchandiseUnit { get; set; }



        public decimal ExchangeRate { get; set; }
    }


    public partial class ImportDetailViewItemBase : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private System.Guid _Id;

        private int _MerchandiseId;

        private double _Quantity;

        private decimal _OriginPrice;

        private int _CurrencyId;

        private decimal _ExchangeRate;

        private double _Tax;

        private decimal _ShippingFee;

        private System.Nullable<double> _UnitPriceAfterTax;

        private string _CreatedBy;

        private System.DateTime _CreatedDate;

        private System.DateTime _LastModifiedDate;

        private System.Guid _ImportId;



        #region Extensibility Method Definitions
        partial void OnLoaded();

        partial void OnCreated();
        partial void OnIdChanging(System.Guid value);
        partial void OnIdChanged();
        partial void OnMerchandiseIdChanging(int value);
        partial void OnMerchandiseIdChanged();
        partial void OnQuantityChanging(double value);
        partial void OnQuantityChanged();
        partial void OnOriginPriceChanging(decimal value);
        partial void OnOriginPriceChanged();
        partial void OnCurrencyIdChanging(int value);
        partial void OnCurrencyIdChanged();
        partial void OnExchangeRateChanging(decimal value);
        partial void OnExchangeRateChanged();
        partial void OnTaxChanging(double value);
        partial void OnTaxChanged();
        partial void OnShippingFeeChanging(decimal value);
        partial void OnShippingFeeChanged();
        partial void OnUnitPriceAfterTaxChanging(System.Nullable<double> value);
        partial void OnUnitPriceAfterTaxChanged();
        partial void OnCreatedByChanging(string value);
        partial void OnCreatedByChanged();
        partial void OnCreatedDateChanging(System.DateTime value);
        partial void OnCreatedDateChanged();
        partial void OnLastModifiedDateChanging(System.DateTime value);
        partial void OnLastModifiedDateChanged();
        partial void OnImportIdChanging(System.Nullable<System.Guid> value);
        partial void OnImportIdChanged();
        #endregion

        public ImportDetailViewItemBase()
        {

            OnCreated();
        }


        public System.Guid Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }


        public int MerchandiseId
        {
            get
            {
                return this._MerchandiseId;
            }
            set
            {
                if ((this._MerchandiseId != value))
                {
                    this.OnMerchandiseIdChanging(value);
                    this.SendPropertyChanging();
                    this._MerchandiseId = value;
                    this.SendPropertyChanged("MerchandiseId");
                    this.OnMerchandiseIdChanged();
                }
            }
        }


        public double Quantity
        {
            get
            {
                return this._Quantity;
            }
            set
            {
                if ((this._Quantity != value))
                {
                    this.OnQuantityChanging(value);
                    this.SendPropertyChanging();
                    this._Quantity = value;
                    this.SendPropertyChanged("Quantity");
                    this.OnQuantityChanged();
                }
            }
        }


        public decimal OriginPrice
        {
            get
            {
                return this._OriginPrice;
            }
            set
            {
                if ((this._OriginPrice != value))
                {
                    this.OnOriginPriceChanging(value);
                    this.SendPropertyChanging();
                    this._OriginPrice = value;
                    this.SendPropertyChanged("OriginPrice");
                    this.OnOriginPriceChanged();
                }
            }
        }


        //public int CurrencyId
        //{
        //    get
        //    {
        //        return this._CurrencyId;
        //    }
        //    set
        //    {
        //        if ((this._CurrencyId != value))
        //        {

        //            this.OnCurrencyIdChanging(value);
        //            this.SendPropertyChanging();
        //            this._CurrencyId = value;
        //            this.SendPropertyChanged("CurrencyId");
        //            this.OnCurrencyIdChanged();
        //        }
        //    }
        //}


        //public decimal ExchangeRate
        //{
        //    get
        //    {
        //        return this._ExchangeRate;
        //    }
        //    set
        //    {
        //        if ((this._ExchangeRate != value))
        //        {
        //            this.OnExchangeRateChanging(value);
        //            this.SendPropertyChanging();
        //            this._ExchangeRate = value;
        //            this.SendPropertyChanged("ExchangeRate");
        //            this.OnExchangeRateChanged();
        //        }
        //    }
        //}


        public double Tax
        {
            get
            {
                return this._Tax;
            }
            set
            {
                if ((this._Tax != value))
                {
                    this.OnTaxChanging(value);
                    this.SendPropertyChanging();
                    this._Tax = value;
                    this.SendPropertyChanged("Tax");
                    this.OnTaxChanged();
                }
            }
        }


        public decimal ShippingFee
        {
            get
            {
                return this._ShippingFee;
            }
            set
            {
                if ((this._ShippingFee != value))
                {
                    this.OnShippingFeeChanging(value);
                    this.SendPropertyChanging();
                    this._ShippingFee = value;
                    this.SendPropertyChanged("ShippingFee");
                    this.OnShippingFeeChanged();
                }
            }
        }


        public System.Nullable<double> UnitPriceAfterTax
        {
            get
            {
                return this._UnitPriceAfterTax;
            }
            set
            {
                if ((this._UnitPriceAfterTax != value))
                {
                    this.OnUnitPriceAfterTaxChanging(value);
                    this.SendPropertyChanging();
                    this._UnitPriceAfterTax = value;
                    this.SendPropertyChanged("UnitPriceAfterTax");
                    this.OnUnitPriceAfterTaxChanged();
                }
            }
        }


        public string CreatedBy
        {
            get
            {
                return this._CreatedBy;
            }
            set
            {
                if ((this._CreatedBy != value))
                {

                    this.OnCreatedByChanging(value);
                    this.SendPropertyChanging();
                    this._CreatedBy = value;
                    this.SendPropertyChanged("CreatedBy");
                    this.OnCreatedByChanged();
                }
            }
        }


        public System.DateTime CreatedDate
        {
            get
            {
                return this._CreatedDate;
            }
            set
            {
                if ((this._CreatedDate != value))
                {
                    this.OnCreatedDateChanging(value);
                    this.SendPropertyChanging();
                    this._CreatedDate = value;
                    this.SendPropertyChanged("CreatedDate");
                    this.OnCreatedDateChanged();
                }
            }
        }


        public System.DateTime LastModifiedDate
        {
            get
            {
                return this._LastModifiedDate;
            }
            set
            {
                if ((this._LastModifiedDate != value))
                {
                    this.OnLastModifiedDateChanging(value);
                    this.SendPropertyChanging();
                    this._LastModifiedDate = value;
                    this.SendPropertyChanged("LastModifiedDate");
                    this.OnLastModifiedDateChanged();
                }
            }
        }


        public System.Guid ImportId
        {
            get
            {
                return this._ImportId;
            }
            set
            {
                if ((this._ImportId != value))
                {

                    this.OnImportIdChanging(value);
                    this.SendPropertyChanging();
                    this._ImportId = value;
                    this.SendPropertyChanged("ImportId");
                    this.OnImportIdChanged();
                }
            }
        }





        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
